package com.wc.AlgoOJ_train.train3_算法大礼包.c3_贪心.AG0406_站岗;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @Author congege
 * @Description
 * @Date Created in 2024/2/1-11:44
 * http://43.138.190.70:8888/p/AG0406
 */
public class Main2 {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 25010;
    static int[][] a = new int[N][2];
    static int n, t;

    public static void main(String[] args) {
        n = sc.nextInt();
        t = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i][0] = sc.nextInt();
            a[i][1] = sc.nextInt();
        }
        Arrays.sort(a, 1, n + 1, Comparator.comparingInt(o -> o[0]));
        int st = a[1][1], ed = t;
        boolean success = false;
        int res = 0;
        for (int i = 1; i <= n; i++) {
            int j = i, maxR = -1;
            while (j <= n && a[j][0] <= st) {
                maxR = Math.max(a[j][1], maxR);
                j++;
            }

            if (maxR < st) {
                break;
            }
            res++;
            if (maxR - a[1][0] + 1 >= ed) {
                success = true;
                break;
            }
            st = maxR;
            i = j - 1;
        }
        if (!success || a[1][0] != 1) {
            res = -1;
        }
        out.println(res);
        out.flush();
    }

    static class FastReader {
        StringTokenizer st;
        BufferedReader br;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        boolean hasNext() {
            while (st == null || !st.hasMoreElements()) {
                String s = nextLine();
                if (s == null) {
                    return false;
                }
                st = new StringTokenizer(s);
            }

            return true;
        }
    }
}
